package com.demo.service;

import com.demo.entity.CtFeedback;
import com.demo.dao.CtFeedbackDao;
import com.demo.entity.dto.CtFeedbackDto;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * (CtFeedback)表服务实现类
 *
 * @author makejava
 * @since 2021-07-03 12:10:10
 */
@Service("ctFeedbackService")
public class CtFeedbackService{
    @Resource
    private CtFeedbackDao ctFeedbackDao;

    /**
     * 新增数据
     *
     * @param ctFeedback 实例对象
     * @return 实例对象
     */
    public CtFeedback insert(CtFeedback ctFeedback) {
        this.ctFeedbackDao.insert(ctFeedback);
        return ctFeedback;
    }

    /**
     * 通过主键删除数据
     *
     * @param fId 主键
     * @return 是否成功
     */
    public boolean deleteById(Integer fId) {
        return this.ctFeedbackDao.deleteById(fId) > 0;
    }

    /**
     * 查询所有的反馈
     * @return
     */
    public List<CtFeedback> findAll() {
        return this.ctFeedbackDao.findAll();
    }

    /**
     * 根据id查询反馈信息
     * @param id
     * @return
     */
    public CtFeedbackDto findById(int id) {
        CtFeedback back = this.ctFeedbackDao.findById(id);
        CtFeedbackDto backDto=new CtFeedbackDto();
        String photos[]=back.getFPictures().split(",");
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < photos.length; i++) {
            list.add(photos[i]);
        }
        backDto.setfPictures(list);
        backDto.setfId(back.getFId());
        backDto.setfContent(back.getFContent());
        backDto.setfPhone(back.getfPhone());
        backDto.setfType(back.getFType());
        backDto.setfUserId(back.getFUserId());
        return backDto;
    }
}
